import { V3proRunStatus } from "../../../api/v3pro-api/v3pro.api.response.model";
import { appConfig } from "../../../configs/env.config.load";

interface TemplateRunStatus {
  deviceInfo: { id: string };
  status: V3proRunStatus;
}

/**
 * 温度检查助手
 */
export class V3proCheckTemplateHelper {
  constructor(private __map = new Map<string, number>()) {}

  check(target: TemplateRunStatus): boolean {
    const {
      deviceInfo: { id },
    } = target;
    const { workingTempC } = target.status.runStatus;
    if (workingTempC < appConfig.v3pro.threshold.temperatureThreshold) {
      this.__map.delete(id);
      return false;
    }
    if (!this.__map.has(id)) {
      this.__map.set(id, Date.now());
    }
    return Date.now() - this.__map.get(id)! > appConfig.v3pro.threshold.temperatureDuration * 1000;
  }
}
